package com.woniuxy.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.entitys.TbDepartment;
import com.woniuxy.entitys.TbOrder;
import com.woniuxy.service.HospitalOrderService;
import com.woniuxy.utils.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author wu
 * @date 2024/01/14 18:22:14
 */
@RestController

public class HospitalOrderController {
    @Autowired
    private HospitalOrderService hospitalOrderService;

        //首先得到登录的科室负责人的账户uid,
        //根据uid找到科室表的hid和did
        //根据hid被did找到bed表中的bid
        //根据bid找到order表中的oid,将订单信息展示出来

    @PostMapping("/getOrder")
    public ResultVO getDepartmentOrder(@RequestBody Map<String,Object> map){

        Integer pageNum = (Integer) map.get("pageNum");
        Integer pageSize = (Integer) map.get("pageSize");
        PageInfo<TbOrder> list = hospitalOrderService.getDepartmentOrder(pageNum,pageSize);
        return  list!=null?ResultVO.success("科室订单查询成功",list):ResultVO.failure("科室订单查询失败");
    }
    @PostMapping("/getByNum")
    public ResultVO getDepartmentOrderByNum(@RequestBody Map<String,Object> map){

        Integer pageNum = (Integer) map.get("pageNum");
        Integer pageSize = (Integer) map.get("pageSize");
        String onumOrBnum = (String) map.get("onumOrBnum");

        PageInfo<TbOrder> list = hospitalOrderService.getDepartmentOrderByNum(pageNum,pageSize,onumOrBnum);
        return  list!=null?ResultVO.success("科室订单查询成功",list):ResultVO.failure("科室订单查询失败");
    }
    @GetMapping("getDepartmentByHid")
    public ResultVO getDepartmentByHid(){
        List<TbDepartment> list = hospitalOrderService.getDepartmentByHid();
        return  list!=null?ResultVO.success("科室订单查询成功",list):ResultVO.failure("科室订单查询失败");
    }




    @PostMapping("/getByDepartOrder")
    public ResultVO getByDepartOrder(@RequestBody Map<String,Object> map){

        Integer pageNum = (Integer) map.get("pageNum");
        Integer pageSize = (Integer) map.get("pageSize");
        Integer did = (Integer) map.get("did");
        PageInfo<TbOrder> list = hospitalOrderService.getByDepartOrder(pageNum,pageSize,did);
        return  list!=null?ResultVO.success("科室订单查询成功",list):ResultVO.failure("科室订单查询失败");
    }
    @GetMapping("updateStatu/{id}")
    public ResultVO updateStatu(@PathVariable("id") Integer oid){

        int i= hospitalOrderService.updateStatu(oid);
        return  i>0?ResultVO.success("状态修改成功"):ResultVO.failure("状态修改失败");
    }





}
